package com.zhongya.example.view

import android.content.Context
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.graphics.Path
import android.util.AttributeSet
import android.view.MotionEvent
import android.view.View

class NormalGestureTrackView : View{

    lateinit var paint : Paint

    val path = Path()

    constructor(context: Context) : super(context) {

    }

    constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) {
        paint = Paint()
        paint.color = Color.YELLOW
        paint.style = Paint.Style.STROKE
        paint.strokeWidth = 2f
    }

    override fun onTouchEvent(event: MotionEvent?): Boolean {

        when(event?.action){
            MotionEvent.ACTION_DOWN -> {
                path.moveTo(event.x,event.y)
                return true
            }
            MotionEvent.ACTION_MOVE -> {
                path.lineTo(event.x,event.y)
                postInvalidate()
            }
        }
        return super.onTouchEvent(event)

    }

    override fun onDraw(canvas: Canvas?) {
        super.onDraw(canvas)

        canvas?.drawColor(Color.WHITE)
        canvas?.drawPath(path,paint)

    }
}